class Solution {
public:
    bool hasPathSum(TreeNode *node, int sum, int curSum)
    {
        if (!node)
            return false;
        
        if (!node->left && !node->right)
            return curSum + node->val == sum;
               
        return hasPathSum(node->left, sum, curSum + node->val) || hasPathSum(node->right, sum, curSum + node->val);
    }
    
    bool hasPathSum(TreeNode *root, int sum) {
        return hasPathSum(root, sum, 0);
    }
};